import { config } from '../../config/index';
import { getUserId } from '../../userData/userData';

// /** 获取收货地址 */
// export function fetchDeliveryAddress(id = 0) {

// }

/** 获取收货地址列表 */
export function fetchDeliveryAddressList() {
  return wx.cloud.callFunction({
    name: "user_getAllAddr",
    data: {
      user_id: getUserId()
    }
  })
}
//添加收货地址
export function addAddressInfo(data) {
  const user_id = getUserId()
  console.log(data)
  return wx.cloud.callFunction({
    name: "user_addAddress",
    data: {
      user_id: user_id,
      content: data.content,
      default: data.default ? 1 : 0,
      address_name: data.address_name,
      address_phone: data.address_phone
    }
  })
}
//删除收货地址
export function delAddressInfo(id) {
  return wx.cloud.callFunction({
    name: "user_deleteAddress",
    data: {
      address_id: id
    }
  })
}
//修改收货地址
export function updateAddressInfo(data) {
  return wx.cloud.callFunction({
    name: "user_updateAddress",
    data: {
      u_id: getUserId(),
      address_id: data._id,
      content: data.content,
      default: data.default == 0 ? 0 : 1,
      address_name: data.address_name,
      address_phone: data.address_phone
    }
  })
}
//修改用户默认收货地址
export function updateDefaultAddressInfo(id) {
  return wx.cloud.callFunction({
    name: "user_swichDefaultAddress",
    data: {
      user_id: getUserId(),
      default_value: id
    }
  })
}